/**
 * 
 */
package org.jenkon.commons.io.comparator;

import java.io.File;

import org.jenkon.commons.io.utils.FilenameUtils;
import org.jenkon.commons.lang.CaseSensitivType;

/**
 * @author Jens Konopka
 * 
 */
public class ExtensionFileComparator implements FileComparator {

	private final CaseSensitivType caseSensitivType;

	/**
	 * 
	 */
	public ExtensionFileComparator() {
		this(CaseSensitivType.INSENSITIVE);
	}

	/**
	 * @param caseSensitivType
	 *            {@link CaseSensitivType}
	 */
	public ExtensionFileComparator(final CaseSensitivType caseSensitivType) {
		this.caseSensitivType = caseSensitivType;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
	 */
	public int compare(final File o1, final File o2) {
		final String ext1 = FilenameUtils.getExtension(o1);
		final String ext2 = FilenameUtils.getExtension(o2);
		if (caseSensitivType.equals(CaseSensitivType.INSENSITIVE)) {
			return ext1.toLowerCase().compareTo(ext2.toLowerCase());
		}
		return ext1.compareTo(ext2);
	}

}
